<template>
	<view class="" style="background-color: #F8F8F8;">
		<view class="nav-back">
			<top-heigth></top-heigth>
			<uv-navbar bg-color="rgba(0,0,0,0)" :fixed="false" title="服务地址" :safeAreaInsetTop="false">
				<template v-slot:right>
					<view class="uv-nav-slot" @click="goAddAddress()">
						<span style="font-size: 30rpx; color: #27A0FF;">新增地址</span>
					</view>
				</template>
				<template v-slot:left>
					<view class="uv-nav-slot" @click="goback()">
						<image src="/static/image/go.png" style="width: 40rpx; height: 40rpx;" mode=""></image>
					</view>
				</template>
			</uv-navbar>
		</view>
		<view v-if="list.length===0" class="kong-box">
			<uv-empty mode="" text="还没有地址，快去添加吧~" icon="/static/image/kong-address.png"></uv-empty>
		</view>
		<view v-if="list.length!=0" class="content-box m-t24">
			<view class="public-box m-b16" v-for="item in list">
				<view class="address-bottom">
					<view class="address-bottom-l" @click="backToOrder(item)">
						<view class="address-top">
							{{item.city}} {{item.district}} {{item.address}}
						</view>
						<h1>{{item.detailAddress}}</h1>
						<view class="address-font">
							<view class="name">{{item.nane}}
								<span v-if="item.sex == 1">（先生）</span>
								<span v-else>（女士）</span>
							</view>
							<view class="font-hui">{{item.phone}}</view>
							<!-- <view class="mr">默认</view> -->
						</view>
					</view>
					<view class="icon-box">
						<uv-icon @click="deleteList(item.id,item.version)" size="40rpx" name="trash" style="margin-right: 16rpx;"></uv-icon>
						<uv-icon  @click="goChangeAddress(item.id)" size="40rpx" name="/static/image/address.png" style="margin-right: 8rpx;"></uv-icon>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import TopHeigth from '@/components/TopHeigth.vue'
	
	export default {
		data() {
			return {
				list: [],
				userInfo: uni.getStorageSync('userInfo'),
				backSign: false
			}
		},
		components: { TopHeigth },
		onLoad(e) {
			this.backSign = e.sign
		},
		onShow(){
			this.getList()
		},
		methods: {
			getList(){
				 uni.$u.http.post('/api/shop/v1_0/tAppUserAddressRCA/queryTAppUserAddress',{
					appUserId: this.userInfo.id,
				}).then((res) => {
					this.list = res.aaData
				}) 
			},
			deleteList(id,version){
				uni.showModal({
					title: '提示',
					content: '确认删除吗？',
					success: (res) => {
						if (res.confirm) {
							uni.$u.http.post('/api/shop/v1_0/tAppUserAddressRCA/deleteTAppUserAddress',{
								id: id,
								version:version
							}).then((res) => {
								this.getList()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
			},
			goAddAddress(){
				uni.navigateTo({
					url:"/pages/order/addAddress"
				})
			},
			goChangeAddress(id){
				uni.navigateTo({
					url:"/pages/order/addAddress?id="+id
				})
			},
			goback(){
				uni.navigateBack()
			},
			backToOrder(address){
				if(this.backSign){
					uni.$emit('selectAddress', address)
					this.goback()					
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	@mixin flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: $direction;
	}
	.uv-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border-radius: 100px;
		border-color: #dadbde;
		padding: 3px 7px;
		opacity: 0.8;
	}
	
	.address-top{
		font-size: 24rpx;
		color: #666;
		margin-bottom: 8rpx
	}
	.address-bottom{
		@include flex;
		align-items: center;
		justify-content: space-between;
		.address-bottom-l{
			h1{
				font-size: 30rpx;
				color: #333;
				margin-bottom: 8rpx
			}
			.address-font{
				@include flex;
				align-items: center;
				justify-content: flex-start;
				.name{
					font-size: 26rpx;
					color: #333;
					margin-right: 16rpx;
				}
				.mr{
					width: 64rpx;
					height: 32rpx;
					background: #EB0C00;
					border-radius: 4rpx;
					color: #fff;
					line-height: 32rpx;
					text-align: center;
					font-size: 20rpx;
					margin-left: 16rpx;
				}
			}
		}
	}
	.icon-box{
		@include flex;
		align-items: center;
		justify-content: space-between;
	}
</style>
